package com.btkjgc.controller;
 
import javax.servlet.http.HttpServletRequest;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.servlet.ModelAndView;

import com.btkjgc.models.AdminUser;
import com.btkjgc.utils.Constant;

@Controller
public class WelcomeController
{
	@RequestMapping(value = { "/" }, method = { RequestMethod.GET })
	public ModelAndView getFirstPage(HttpServletRequest request)
	{
		return new ModelAndView("redirect:/login");
	}
	
	
	@SuppressWarnings("unchecked")
	@RequestMapping(value = { "index" }, method = { RequestMethod.GET,
			RequestMethod.POST })
	public ModelAndView index(HttpServletRequest request)
	{
		ModelAndView mv;
		AdminUser adminUser = (AdminUser) request.getSession().getAttribute("user");
		Integer entity_id = adminUser.getEntityid();
 
 
		if (entity_id == Constant.ADMIN_ENTITY)
		{// 超级管理员
			mv = new ModelAndView("index");
		}
		else
		{
			request.getSession().setAttribute("entityid", entity_id);
			mv = new ModelAndView("car_map");
			mv.addObject("entityid", entity_id);
		}
 
		AdminUser au = (AdminUser) request.getSession().getAttribute("user");
		mv.addObject("username", au.getUsername());
 
		return mv;
	}
}
